#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Blue

extern double step = 0.03;
extern double maximum = 0.3;


double highPointBuffer[];
double lowPointBuffer[];

double preHighPoint, preLowPoint;
datetime preHighPointTime, preLowPointTime;

int init()
{
 //  IndicatorBuffers(3);
//---- drawing settings
    SetIndexStyle(0,DRAW_LINE);
    SetIndexStyle(1,DRAW_LINE);
    SetIndexBuffer(0,highPointBuffer);
    SetIndexBuffer(1,lowPointBuffer);

    string short_name="ParabolicSwing("+step+","+maximum+")";
    IndicatorShortName(short_name);
    SetIndexLabel(0,short_name);
    //----
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexStyle(1,DRAW_ARROW);
}

int start()
{
    int i,counted_bars=IndicatorCounted();
    int limit=Bars-counted_bars-1;
    for(i=limit; i>=0; i--)
    {
        double sar = iSAR(NULL,0,step,maximum,i);
        if (sar > High[i])
        {   
            if (i == Bars-1)
            {
                lowPointBuffer[i] = Low[i];
                preLowPoint = Low[i];
                preLowPointTime = Time[i];
            }
            else
            {
                double preSar = iSAR(NULL,0,step,maximum,i+1);
                if (preSar < Low[i+1])
                {
                    lowPointBuffer[i] = Low[i];
                    preLowPoint = Low[i];
                    preLowPointTime = Time[i];
                }
                else
                {
                    if (Low[i] < preLowPoint)
                    {
                        if (preLowPointTime != Time[i])
                        {
                            int shift = iBarShift(NULL,0,preLowPointTime);
                            lowPointBuffer[shift] = 0;
                        }
                        lowPointBuffer[i] = Low[i];
                        preLowPoint = Low[i];
                        preLowPointTime = Time[i];
                    }
                }  
            }  
        }
        
        
        if (sar < Low[i])
        {   
            if (i == Bars-1)
            {
                highPointBuffer[i] = High[i];
                preHighPoint = High[i];
                preHighPointTime = Time[i];
            }
            else
            {
                preSar = iSAR(NULL,0,step,maximum,i+1);
                if (preSar > High[i+1])
                {
                    highPointBuffer[i] = High[i];
                    preHighPoint = High[i];
                    preHighPointTime = Time[i];
                }
                else
                {
                    if (High[i] > preHighPoint)
                    {
                        if (preHighPointTime != Time[i])
                        {
                            shift = iBarShift(NULL,0,preHighPointTime);
                            highPointBuffer[shift] = 0;
                        }
                        highPointBuffer[i] = High[i];
                        preHighPoint = High[i];
                        preHighPointTime = Time[i];
                    }
                }  
            }  
        }
    }
    return(0);
}